import 'package:flutter/material.dart';

class HomeNav extends StatelessWidget {
  const HomeNav({super.key, required this.navList});
  final List navList;
  @override
  Widget build(BuildContext context) {
    return GridView.builder(
      gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 5,
        mainAxisSpacing: 0,
        crossAxisSpacing: 0,
        childAspectRatio: 1,
      ),
      itemBuilder: (BuildContext context, int index) {
        return Container(
          color: Colors.white,
          alignment: Alignment.center,
          child: Container(
            padding: const EdgeInsets.all(2),
            child: Column(
              children: [
                Expanded(
                  child: Image.network(
                    navList[index]['imgUrl'],
                    width: 60,
                    height: 60,
                    fit: BoxFit.contain,
                  ),
                ),
                Expanded(
                  child: Text(
                    navList[index]['text'],
                    style: const TextStyle(fontSize: 13),
                  ),
                )
              ],
            ),
          ),
        );
      },
      itemCount: navList.length,
      // 使用 shrinkWrap 属性来优化滚动性能
// 当列表或滚动视图的子元素数量较少时，设置 shrinkWrap 为 true 可以使滚动视图仅占用实际需要的空间
// 这样可以减少渲染开销，提升应用性能
      shrinkWrap: true,
    );
  }
}
